package com.friendc.Controller;

import com.alibaba.fastjson.JSON;
import com.friendc.PrJo.User;
import com.friendc.PrJo.friendc;
import com.friendc.Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @Author 20424
 * @Date 2020/8/6 14:32
 * @Version 1.0
 */
@WebServlet(name = "MyFriendController")
public class MyFriendController extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//设置请求域编码格式
        //设置响应编码格式
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        int title= Integer.parseInt(request.getParameter("title"));
        //System.out.print(title);
        //2.从session中获取
        HttpSession session=request.getSession();//获取前台session
        User use = (User) session.getAttribute("user");
        UserService user=new UserService();
        List<friendc> obj=user.findByfriend(use.username,title);
        //2.在转换的同时格式化时间格式（“1”在friendc类中）
        String json= JSON.toJSONStringWithDateFormat(obj,"yyyy-MM-dd");//对象转json,同时规定时间格式
        //System.out.print(json);
        //将jsons数据返回前端
        response.getWriter().print(json);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
